'use strict';

const fs = require('fs');
const path = require('path');
const {
  app: electronApp, dialog, shell, Notification, 
} = require('electron');
const { logger } = require('ee-core/log');
const { dbService } = require('../service/database/db');

/**
 * db
 * @class
 */
class DbController {
  async test () {
    logger.info('test');
    return 'hello electron-egg';
  }

  async insert(data) {
    logger.info('insert');
    const result = await dbService.insert(data);

    const ret = {
      msg: null,
      data: [],
      code: result ? 0 : -1
    };
    return ret;
  }

  async delete(name) {
    logger.info('delete');
    const result = await dbService.delete(name);
    return result;
  }

  async query(args) {
    logger.info('query args {}', args);
    const { search_age, search_name } = args;

    const ret = {
        msg: null,
        data: [],
        code: 0
    };

    ret.data = await dbService.get(args.search_name, args.search_age);
    return ret;
  }

  async update(data) {
    logger.info('update');
    const result = await dbService.update(data);
    return result;
  }

}
DbController.toString = () => '[class DbController]';

module.exports = DbController; 